<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>


        // 寄生式继承：子类的prototype 指向 父类的 prototype   ----- 地址共享


        function Person(name, age) {
            this.type = '人';
            this.name = name;
            this.age = age;
        }
        Person.prototype.say = function () {
            console.log('hi');
        }



        function Student(grade, score, name, age) {
            this.grade = grade;
            this.score = score;

            Person.call(this, name, age);
        }

        // 继承父类的原型上的方法
        // Student.prototype = Person.prototype;     // 浅拷贝

        Student.prototype = { ...Person.prototype };   // 深拷贝


        // 添加自己的方法
        Student.prototype.speak = function () {
            console.log('hi 我考了' + this.score + '分');
        }


        const s = new Student('3', 100, 'cc', 20);
        console.log(s);


        const p = new Person('cc', 20);
        console.log(p);


    </script>

</body>

</html>